const db=uniCloud.database();
const dbCmd = db.command;
module.exports = {
	_before: function () { // 通用预处理器

	},
		
	async addOrder(user_id,snack_id,number,total){
		let res =await db.collection("order").add({
			user_id,
			snack_id,
			number,
			total,
			state:0,
			
		})
		return res
	},
	
	async getLatestOrder(){
		let res =await db.collection("order").limit(1).orderBy("desc").get();
		return res;
	},
	
	async updateOrder(id,value){
		let res =await db.collection("order").where({
			_id:id
		}).update({
			state:value
		})
		return res
	},
	
	async getmyOrder(user_id){
		let res =await db.collection("order").where({
			user_id
		}).get();
		return res
	},
	
	async getOrderbyState(user_id,snack_id){
		let res =await db.collection("order").where({
			user_id,
			snack_id,
			state:0
		}).get();
		return res
	}
}
